package com.xsystem.user.dao;

import org.hibernate.HibernateException;

import com.xsystem.criteria.XsystemCriteria;
import com.xsystem.criteria.XsystemExpression;
import com.xsystem.orm.user.User;
import com.xsystem.util.GenericDAO;

public class UserDAO extends GenericDAO {

	public User findUserByUsername(String username) {
		User user = null;
		try {
			// query: select id, username, password from User where username =
			// "{$username}"
			XsystemCriteria criteria = XsystemCriteria.forClass(User.class)
					.with(XsystemExpression.eq("username", "String", username));
			user = (User) this.findUniqueResultByDetachedCriteria(criteria
					.toHibernateDetachedCriteria());
		} catch (HibernateException he) {
			he.printStackTrace();
		} catch (ClassCastException cce) {
		}
		return user;
	}

//	public User findUserByUsername(String username) {
//		try {
//			return (User) this.getSession()
//					.createQuery("from User u where u.username = :username")
//					.setParameter("username", username).uniqueResult();
//		} catch (HibernateException ex) {
//			ex.printStackTrace();
//			return null;
//		}
//	}
}
